@include('admin.public.head')

<div class="ibox-title">
    <h5>課程添加</h5>
</div>

<div class="ibox-content">
    <form class="form-horizontal">

        <div class="form-group">
            <label class="col-sm-3 control-label">門店分類：</label>
            <div class="col-sm-9">
                <select class="form-control" name="store_id" id="store_id">
                    <option value="">請選擇門店</option>
                    @foreach($select_store as $k=>$v)
                        <option value="{{$k}}" @if($select_id == $k) selected="selected" @endif>{{$v}}</option>
                    @endforeach
                </select>
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">請選擇課程編號：</label>
            <div class="col-sm-9">
                <select class="form-control" name="class_base_numbering_id" id="class_base_numbering_id">
                    <option value="">請選擇課程編號</option>
                    @foreach($select_class_base_numbering as $k=>$v)
                        <option value="{{$v->id}}"
                                @if($class_base_numbering_id == $v->id) selected="selected" @endif>{{$v->numbering}}</option>
                    @endforeach
                </select>
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">課程名稱：</label>
            <div class="col-sm-9">
                <input type="text" name="class_name" class="form-control" placeholder="課程名稱"
                       value="{{$result->class_name??''}}">
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">課程標簽欄：</label>
            <div class="col-sm-9">
                <input type="text" name="class_tab" class="form-control" placeholder="課程標簽欄"
                       value="@if(!empty($result->class_tab))@php echo implode(",",$result->class_tab); @endphp@endif">
                注：,逗号隔开填多个
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">上課服裝：</label>
            <div class="col-sm-8">
                <script id="class_clothing" name="content" type="text/plain"
                        style="height:300px;">{!! $result->class_clothing??'' !!}</script>
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">上課faq：</label>
            <div class="col-sm-8">
                <script id="class_faq" name="content" type="text/plain"
                        style="height:300px;">{!! $result->class_faq??'' !!}</script>
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">上課注意事項：</label>
            <div class="col-sm-8">
                <script id="class_note" name="content" type="text/plain"
                        style="height:300px;">{!! $result->class_note??'' !!}</script>
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        {{--        <div class="form-group">--}}
        {{--            <label class="col-sm-3 control-label">課程介紹：</label>--}}
        {{--            <div class="col-sm-8">--}}
        {{--                <script id="class_introduction" name="content" type="text/plain" style="height:300px;">{!! $result->class_introduction??'' !!}</script>--}}
        {{--            </div>--}}
        {{--        </div>--}}
        {{--        <div class="hr-line-dashed"></div>--}}

        <div class="form-group">
            <label class="col-sm-3 control-label">适合人群：</label>
            <div class="col-sm-8">
                <script id="crowd" name="crowd" type="text/plain"
                        style="height:300px;">{!! $result->crowd??'' !!}</script>
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">圖片：</label>
            <div class="col-sm-9">
                <input type="file" name="class_cove" class="form-control" value="">

                <input type="hidden" name="class_cove_is_null" value="0">

                <div style="position:relative;margin-top: 15px">
                    @if(!empty($result->class_cove))
                        <img src="{{$result->class_cove??''}}" id="class_cove_img" width="300" height="150">

                        <a href="javascipt:void(0)" onclick="clear_class_cove($(this))"
                           class="glyphicon glyphicon-remove" style="position: absolute;font-size: 20px"></a>
                    @endif
                </div>
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">視頻：</label>
            <div class="col-sm-9">
                <input type="file" name="class_video" class="form-control" value="">

                <input type="hidden" name="class_video_is_null" value="0">

                <div style="position:relative;margin-top: 15px">
                    @if(!empty($result->class_video))
                        <embed src="{{$result->class_video??''}}" id="class_cove_video" height="200" width="200">

                        <a href="javascipt:void(0)" onclick="clear_class_video($(this))"
                           class="glyphicon glyphicon-remove" style="position: absolute;font-size: 20px"></a>
                    @endif
                </div>
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">課程價格：</label>
            <div class="col-sm-9">
                <input type="number" min="0" name="class_price" class="form-control" placeholder="課程價格"
                       value="{{$result->class_price??''}}">
            </div>
        </div>
        <div class="hr-line-dashed"></div>


        <input type="hidden" name="id" value="{{$id??0}}">

        <div class="form-group">
            <div class="col-sm-4 col-sm-offset-3">
                <button class="btn btn-primary do" type="submit">操作</button>
                <a href="/class_base" class="btn btn-primary">返回課程列表</a>
            </div>
        </div>
    </form>
</div>

<script>

    function clear_class_cove(obj) {
        $("#class_cove_img").remove();
        obj.remove();
        $('input[name="class_cove_is_null"]').val(1);
    }

    function clear_class_video(obj) {
        $("#class_cove_video").remove();
        obj.remove();
        $('input[name="class_video_is_null"]').val(1);
    }

    var class_clothing = UE.getEditor('class_clothing');
    var class_faq = UE.getEditor('class_faq');
    var class_note = UE.getEditor('class_note');
    //var class_introduction = UE.getEditor('class_introduction');
    var crowd = UE.getEditor('crowd');


    $('.do').click(function () {
        var form = new FormData();

        var store_id = $('#store_id option:selected').val();
        var class_base_numbering_id = $('#class_base_numbering_id option:selected').val();

        var class_tab = $('input[name="class_tab"]').val();
        var class_name = $('input[name="class_name"]').val();
        var class_price = $('input[name="class_price"]').val();
        var class_cove_is_null = $('input[name="class_cove_is_null"]').val();
        var class_video_is_null = $('input[name="class_video_is_null"]').val();
        var id = $('input[name="id"]').val();

        var class_clothing_content = class_clothing.getContent();
        var class_faq_content = class_faq.getContent();
        var class_note_content = class_note.getContent();
        //var class_introduction_content = class_introduction.getContent();
        var class_crowd = crowd.getContent();

        var class_cove = $('input[name="class_cove"]')[0].files[0];
        var class_video = $('input[name="class_video"]')[0].files[0];

        form.append("store_id", store_id);
        form.append("class_base_numbering_id", class_base_numbering_id);
        form.append("class_name", class_name);
        form.append("id", id);
        form.append("class_tab", class_tab);
        form.append("class_clothing", class_clothing_content);
        form.append("class_faq", class_faq_content);
        form.append("class_note", class_note_content);
        //form.append("class_introduction", class_introduction_content);
        form.append("class_cove", class_cove);
        form.append("class_video", class_video);
        form.append("class_price", class_price);
        form.append("crowd", class_crowd);
        form.append("class_cove_is_null", class_cove_is_null);
        form.append("class_video_is_null", class_video_is_null);

        $.ajax({
            type: 'POST',
            url: '/class_do',
            dataType: "json",   //返回格式为json
            data: form,
            processData: false,
            contentType: false,
            success: function (data) {

                if (data.status == '1') {
                    var swal_json = {
                        title: data.message,
                        type: "success"
                    }

                    swal(swal_json, function (isConfirm) {
                        window.location.reload();
                    });

                } else {
                    var swal_json = {
                        title: data.message,
                        type: "error"
                    }

                    swal(swal_json, function (isConfirm) {

                    });
                }
            }
        });

        return false;
    });
</script>
